<template>
    <div>
        <H1>科室管理</H1>
        科室名称:<input type="text" v-model="infoo.name">
          <select v-model="infoo.lid">
            <option value="">请选择</option>
            <option :value="item.oid" v-for="item in level" :key="item.oid">{{item.oname}}</option>  
        </select>
        <input type="button" value="查询" @click="GetList" style="background-color:cyan;">
        <table class="table table-bordered"  style="background-color:cadetblue;">
          <tbody>
              <tr>
                <td>科室名称</td>
                <td>科室人数</td>
                <td>科室描述</td>
                <td>创建日期</td>
                <td>操作</td>
            </tr>
            <tr v-for="value in info">
                <td>{{value.name}}</td>
                <td>{{value.people}}</td>
                <td>{{value.introduce}}</td>
                <td>{{value.createTime.substr(0,10)}}</td>
                <td><input type="button" value="查看" @click="fan(value.id)" style="background-color: cornflowerblue;">
                    <input type="button" value="修改" @click="update(value.id)" style="background-color:bisque;">
                    <input type="button" value="删除" @click="Del(value.id)" style="background-color: brown;">
                </td>
            </tr>
          </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'
import axios from 'axios';
import { onMounted } from 'vue';
import { useRoute,useRouter } from 'vue-router';
let route=useRoute();
let router=useRouter();

let info:any=ref([]);
let level:any=ref([]);
let infoo:any=ref({
    name:"",
    lid:""
})

//删除 
const Del=(id:any)=>{
    let f=(confirm("确认要删除吗?"))
    axios({
        url:'https://localhost:7118/api/Office/Del',
        method:'delete',
        params:{
            id:id
        }
    })
    .then((res)=>{
        console.log(res);
        if(res.data>0){
            alert("删除成功!")
            location.href='/officeshow'
        }
        else
        {
            alert("删除失败")
            return;
        }
    })
    .catch((err)=>{
        console.log(err);
    })
}

//跳转反填
const fan=(id:any)=>{
    router.push({
        path:'/officefan',
        query:{
            id:id
        }
    })
}
//跳转修改
const update=(id:any)=>{
    router.push({
        path:'/officeupdate',
        query:{
            id:id
        }
    })
}

onMounted(()=>{
    GetList();
    GetLevel();
})
const GetList=()=>{
    axios({
        url:'https://localhost:7118/api/Office/GetOffices',
        method:'get',
        params:infoo.value   
    })
    .then((res)=>[
        console.log(res),
        info.value=res.data
    ])
    .catch((err)=>{
        console.log(err);
    })
}

const GetLevel=()=>{
      axios({
        url:'https://localhost:7118/api/Office/GetOfficeLevels',
        method:'get',
    })
    .then((res)=>[
        console.log(res),
        level.value=res.data
    ])
    .catch((err)=>{
        console.log(err);
    })
}

</script>

<style scoped>

</style>